import 'package:json_annotation/json_annotation.dart';

part 'comic_category_item_model.g.dart';

@JsonSerializable()
class ComicCategoryData {
  final String? title;
  final int? moreType;
  final List<ComicItemModel>? comics;

  ComicCategoryData({
    this.title,
    this.moreType,
    this.comics,
  });

  factory ComicCategoryData.fromJson(Map<String, dynamic> json) =>
      _$ComicCategoryDataFromJson(json);

  Map<String, dynamic> toJson() => _$ComicCategoryDataToJson(this);
}

@JsonSerializable()
class ComicItemModel {
  final String? author;
  final int? bookRating;
  final int? status;
  final int? comicType; // 0 是免费 1 是付费
  @JsonKey(name: 'categoryId')
  final String? categoryId;
  final String? title;
  final String? desc;
  final String? cover;
  final int? favoriteNum;
  final int? readNum;
  final int? type;
  final int? viewNum;
  final int? recommendSort;
  @JsonKey(name: 'countryCode')
  final String? countryCode;
  final int? isComplete;
  final String? id;
  final String? key;

  ComicItemModel({
    this.author,
    this.bookRating,
    this.status,
    this.comicType,
    this.categoryId,
    this.title,
    this.desc,
    this.cover,
    this.favoriteNum,
    this.readNum,
    this.type,
    this.viewNum,
    this.recommendSort,
    this.countryCode,
    this.isComplete,
    this.id,
    this.key,
  });

  factory ComicItemModel.fromJson(Map<String, dynamic> json) =>
      _$ComicItemModelFromJson(json);

  Map<String, dynamic> toJson() => _$ComicItemModelToJson(this);

  // 扩展方法：获取封面图片URL（添加基础URL）
  String get coverUrl {
    return cover != null ? 'https://your-cdn.com/$cover' : '';
  }
}
